package com.synjones.beijing.controls
{
    import mx.rpc.events.FaultEvent;
    import mx.controls.ComboBox;
    import mx.collections.*;
    import mx.rpc.AbstractService;
    import mx.rpc.AsyncToken;
    import mx.rpc.events.ResultEvent;
    import mx.utils.ArrayUtil;
	import com.synjones.beijing.*;
	import mx.controls.Alert;
	import flash.events.Event;
    
    public class ComboBoxPID extends ComboBox
    {
	    [Bindable]
	    private var pids:ArrayCollection;
	    
    	private var service:AbstractService;
    	
    	public function Init() : void{
    		service = ServiceLocator.getRestaurantService();
    		var token: AsyncToken = AsyncToken(service.GetPIDs());
            token.addResponder(new TokenResponder(getResult, "获取身份信息失败"));
    	}
    	private function getResult(event:ResultEvent):void{  
    	    pids = event.result as ArrayCollection;
    	    pids.addItemAt(new PID("全部","全部"),0);
    	    this.dataProvider = pids;
            this.labelField = "Name";
        }
              
        public function ComboBoxPID(){
            super();
        }
        
        private var _selectedPID:PID;        
        
        public function set selectedPID(data:PID):void{
            var i:int = 0;
            for(i=0;i<pids.length;i++)
            {
                if(pids[i].Code == data.Code)
                {
                    this.selectedIndex = i;
                    return;
                }
            }
            this.selectedIndex = 0;
        }
        [Bindable("change")]
    	[Bindable("collectionChange")]
        [Bindable("valueCommit")]
        public function get selectedPID():PID{
            return new PID(this.selectedItem.Code,this.selectedItem.Name);
        }
    }
}